<!DOCTYPE html>
<html>
<head>
    <include file="./Application/Home/View/Tpl/head.html"/>
</head>
<body class="    fixed-header theme-blue-gradient">
<div id="theme-wrapper">
    <include file="./Application/Home/View/Tpl/header.html"/>
    <input type="hidden" id="wzwifivalue" value="0">
    <div id="page-wrapper" class="container">
        <div class="row">
            <include file="./Application/Home/View/Tpl/menu.html"/>

            <div id="content-wrapper">
                <div class="row">
                    <include file="./Application/Home/View/Tpl/alert.html"/>

                    <div class="col-lg-12">
                        <empty name="setcard">
                            <div class="col-md-12">
                                <div class="alert alert-danger alert-dismissable">
                                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                                    <h4><i class="icon fa fa-ban"></i> 系统提示</h4>
                                    组件加载失败，请检查数据库和网络！
                                </div>
                            </div>
                            <else />
                        </empty>


                        <div class="row">
                            <div class="col-md-12 ">
                                <div class=" ">
                                    <p>设备当前GPS经纬度：<span class="label label-success" id="gps">获取中... ...</span>
                                    <button class="btn btn-primary" id="getroutemap">查看实时位置</button>
                                    </p>
                                </div>
                            </div>
                            <div class="col-md-4 col-sm-6 col-xs-12">
                                <div class="main-box small-graph-box green-bg">
                                    <span class="value">{$setcard[0].carddesc}</span>

                                    <div class="progress">
                                        <div style="width: 100%;" aria-valuemax="100" aria-valuemin="0"
                                             aria-valuenow="100" role="progressbar" class="progress-bar">
                                        </div>
                                    </div>
                                    <span class="subinfo">
                                        <if condition="$setcardstatus[0]['sysstate'] eq 'running' ">

                                            <span class="label label-success"><i class="fa fa-check-circle"></i>
                                                正常运行中</span>
                                            <else />
                                            <span class="label label-default"><i class="fa fa-close"></i>
                                                组件已停止</span>
                                        </if>
                                    </span>
                                    <span class="subinfo">
                                       &nbsp;
                                    </span>
                                </div>
                            </div>
                            <div class="col-md-4 col-sm-6 col-xs-12">
                                <div class="main-box small-graph-box emerald-bg">
                                    <span class="value">{$setcard[1].carddesc}</span>
                                    <div class="progress">
                                        <div style="width: 100%;" aria-valuemax="100" aria-valuemin="0"
                                             aria-valuenow="100" role="progressbar" class="progress-bar">
                                        </div>
                                    </div>
                                    <span class="subinfo">
                                        <if condition="$setcardstatus[1]['sysstate'] eq 'running' ">

                                            <span class="label label-success"><i class="fa fa-check-circle"></i>
                                                正常运行中</span>
                                            <else />
                                            <span class="label label-default"><i class="fa fa-close"></i>
                                                组件已停止</span>
                                        </if>
                                    </span>
                                    <span class="subinfo">
                                       &nbsp;
                                    </span>
                                </div>
                            </div>
                            <div class="col-md-4 col-sm-6 col-xs-12">
                                <div class="main-box small-graph-box  red-bg">
                                    <span class="value">{$setcard[2].carddesc}</span>
                                    <div class="progress">
                                        <div style="width: 100%;" aria-valuemax="100" aria-valuemin="0"
                                             aria-valuenow="100" role="progressbar" class="progress-bar">
                                        </div>
                                    </div>
                                    <span class="subinfo">
                                        <if condition="$setcardstatus[2]['sysstate'] eq 'running' ">

                                            <span class="label label-success"><i class="fa fa-check-circle"></i>
                                                正常运行中</span>
                                            <else />
                                            <span class="label label-default"><i class="fa fa-close"></i>
                                                组件已停止</span>
                                        </if>
                                    </span>
                                    <span class="subinfo">
                                       &nbsp;
                                    </span>
                                </div>
                            </div>
                            <div class="col-md-4 col-sm-6 col-xs-12">
                                <div class="main-box small-graph-box yellow-bg">
                                    <span class="value">{$setcard[3].carddesc}</span>
                                    <div class="progress">
                                        <div style="width: 100%;" aria-valuemax="100" aria-valuemin="0"
                                             aria-valuenow="100" role="progressbar" class="progress-bar">
                                        </div>
                                    </div>
                                    <span class="subinfo">
                                        <if condition="$setcardstatus[3]['sysstate'] eq 'running' ">

                                            <span class="label label-success"><i class="fa fa-check-circle"></i>
                                                正常运行中</span>
                                            <else />
                                            <span class="label label-default"><i class="fa fa-close"></i>
                                                组件已停止</span>
                                        </if>
                                        <button class="btn   btn-success  btn-lg wzwifi pull-right" id="mainwzwifi" action="start"   type="button"  >
                                             开始伪装
                                        </button>
                                    </span>
                                    <span class="subinfo">
                                       &nbsp;
                                    </span>
                                </div>
                            </div>
                            <div class="col-md-4 col-sm-6 col-xs-12">
                                <div class="main-box small-graph-box purple-bg">
                                    <span class="value">蜜罐</span>
                                    <div class="progress">
                                        <div style="width: 0%;" aria-valuemax="100" aria-valuemin="0"
                                             aria-valuenow="0" role="progressbar" class="progress-bar">
                                        </div>
                                    </div>
                                    <if condition="$miguanstatus['ssid'] neq null">
                                                <span id="miguanstatus">
                                                    蜜罐运行中... ...
                                                </span>
                                        <else />
                                        <span id="miguanstatus">&nbsp;</span>
                                    </if>
                                    <span class="subinfo">


                                        <if condition="$miguanstatus['ssid'] neq null">
                                            <button class="btn   btn-success  btn-lg miguan pull-left" id="miguan" action="stop"   type="button"  >
                                                关闭蜜罐
                                            </button>
                                            <else />
                                            <button class="btn    btn-danger  btn-lg miguan pull-left" id="miguan" action="start"    type="button" >
                                                开启蜜罐
                                            </button>
                                        </if>
                                    </span>
                                    <span class="subinfo">
                                       &nbsp;

                                    </span>
                                </div>
                            </div>

                            <div class="col-md-4 col-sm-6 col-xs-12">
                                <div class="main-box small-graph-box green-bg">
                                    <span class="value">全信道压制</span>
                                    <div class="progress">
                                        <div style="width: 0%;" aria-valuemax="100" aria-valuemin="0"
                                             aria-valuenow="0" role="progressbar" class="progress-bar">
                                        </div>
                                    </div>
                                    <if condition="$qxdyazhistatus  eq 'start'">
                                                <span id="qxdyazhistatus">
                                                    全信道压制运行中... ...
                                                </span>
                                        <else />
                                        <span id="qxdyazhistatus">&nbsp;</span>
                                    </if>
                                    <span class="subinfo">


                                        <if condition="$qxdyazhistatus  eq 'start'">
                                            <button class="btn   btn-success  btn-lg miguan pull-left" id="mainqxdyazhi" action="stop"   type="button"  >
                                                关闭全信道压制
                                            </button>
                                            <else />
                                            <button class="btn    btn-danger  btn-lg miguan pull-left" id="mainqxdyazhi" action="start"    type="button" >
                                                开启全信道压制
                                            </button>
                                        </if>
                                    </span>
                                    <span class="subinfo">
                                       &nbsp;

                                    </span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div  draggable="true" class="main-box small-graph-box emerald-bg" id="showstatus" style="    position: fixed;bottom: 0px; right: 15px;width: 40%;z-index: 10000;opacity: 0.9">
                    <span class="value" style="font-size: 1.2em;" id="currentstatuslabel">当前任务</span>
                    <div class="progress">
                        <div style="width: 0%;" aria-valuemax="100" aria-valuemin="0" aria-valuenow="60" role="progressbar" class="progress-bar">

                        </div>
                    </div>
                    <div id="subcurrentstatuslabel">
                        <span class="subinfo" id="crackwifistatus" >  </span>
                        <span class="subinfo" id="wzwifistatus" >  </span>
                        <span class="subinfo" id="attackwifistatus" >  </span>
                    </div>
                </div>
                <include file="./Application/Home/View/Tpl/footer.html"/>

            </div>
        </div>
    </div>
</div>

<div class="modal   fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">手工伪装设置</h4>
            </div>
            <div class="modal-body">
                <div class="form-group  ">
                    <label class="control-label" for="ssid"> SSID</label>
                    <input type="text" class="form-control"  id="ssid" placeholder="请填写伪装的SSID名称 ...">
                </div>
                <div class="form-group  ">
                    <label class="control-label" for="xd"> 信道</label>
                    <input type="tel" class="form-control" id="xd" placeholder="请填写信道 ...">
                </div>

                <div class="form-group  ">
                    <label class="control-label" for="encrypt"> 加密方式</label>
                    <select class="form-control"  id="encrypt" >
                        <option value="WPA">WPA</option>
                        <option value="WPA2">WPA2</option>
                        <option value="WPA-WPA2">WPA/WPA2</option>
                        <option value="WEP">WEP</option>
                        <option value="NONE">OPEN</option>
                    </select>
                </div>
                <div class="form-group  ">
                    <label class="control-label" for="key"> 加密秘钥</label>
                    <input type="text" class="form-control" id="key" placeholder="请填写加密秘钥 ...">
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary  btn-lg" id="wzwifi">开始伪装</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

<div class="modal   fade miguanmodal" id="myModalmiguan" tabindex="-1" role="dialog" aria-labelledby="myModalmiguan" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">蜜罐设置</h4>
            </div>
            <div class="modal-body">
                <div class="form-group  ">
                    <input type="file" id="filenames" />
                    <div id="text"></div>
                </div>

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-danger  btn-lg" id="setmiguan">开启蜜罐</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

<div class="modal   fade" id="myrouteModal" tabindex="-1" role="dialog" aria-labelledby="myrouteModalLabel" aria-hidden="true">
    <div class="modal-dialog" style="width: 100%;margin: 0px">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myrouteModalLabel">设备实时位置</h4>
            </div>
            <div class="modal-body">
                <div class="row">

                    <div id="allmap" style="height:420px;width:100%;"></div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" data-dismiss="modal"  class="btn btn-success btn-lg" >关 闭</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

<input type="hidden" id="uploadfilecontent" name="uploadfilecontent">

<input type="hidden" id="wzssid" name="wzssid">
<input type="hidden" id="wzxd" name="wzxd">
<input type="hidden" id="wzkey" name="wzkey">
<input type="hidden" id="wzencrypt" name="wzencrypt">
<input type="hidden" id="wzapmac" name="wzapmac">

</body>
<include file="./Application/Home/View/Tpl/commjs.html"/>
<script src="__PUBLIC__/js/alertsetting.js"></script>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=kaRXcPncFqA676tqP7vR6MqT4cQqQ0p7"></script>

<script type="text/javascript">
    $("#currentstatuslabel").click(function () {
        if($("#showstatus").css('width')=='55px')
            $("#showstatus").css('width','40%');
        else
            $("#showstatus").css('width','55px');
        $("#subcurrentstatuslabel").toggle();
    })

    //获取当前ap是否正在破解或攻击或伪装
    $.ajax({
        url : "{:U('/Home/scanwifi/getstatus','',false)}",
        type : "post",
        dataType : "json",
        data: null,
        timeout:6000,
        success:function(result){
            console.log(result);
            if(result.status==true){
                if(result.data.crack!=''){
                    var htmls='SSID<span class="label label-success label-large">'+result.data.crack['ssid']+'</span> | mac'+
                        '<span class="label label-success label-large">' +result.data.crack['mac']+'</span>'+ '正在破解中';
                    //htmls+='<button class="btn btn-info ">停止破解</button>';
                    $("#crackwifistatus").html(htmls);
                }
                else{
                    $("#crackwifistatus").html('暂无破解任务');
                }
                if(result.data.wz!=''){
                    var htmls='SSID<span class="label label-success  ">'+result.data.wz['ssid']+'</span> 秘钥'+
                        '<span class="label label-danger  ">' +result.data.wz['encrykey']+'</span> '+
                        '<span class="label label-default ">' +result.data.wz['encrytype']+'</span>'+ '正在伪装中';
                    //htmls+='<button class="btn btn-success  ">停止伪装</button>';
                    $("#wzwifistatus").html(htmls);
                    $("#mainwzwifi").attr('action','stop');
                    $("#mainwzwifi").html('伪装运行中');

                    $('#wzxd').val(result.data.wz['channel']);
                    $('#wzssid').val(result.data.wz['ssid']);
                    $('#wzencrypt').val(result.data.wz['encrytype']);
                    $('#wzapmac').val(result.data.wz['mac']);
                    $('#wzkey').val(result.data.wz['encrykey']);
                }else
                {
                    $("#wzwifistatus").html('暂无伪装任务');
                    $("#mainwzwifi").html('开始伪装');
                }
                if(result.data.attack!=''){
                    var htmls='SSID<span class="label label-success label-large">'+result.data.attack['ssid']+'</span> | mac'+
                        '<span class="label label-success label-large">' +result.data.attack['mac']+'</span>'+ '正在攻击中';
                    //htmls+='<button class="btn btn-danger   ">停止攻击</button>';
                    $("#attackwifistatus").html(htmls);
                }else{
                    $("#attackwifistatus").html('暂无攻击任务');
                }

            }
        },
        error:function(msg){
            console.log(msg);
        }
    });

    function getmacalert() {
        $.ajax({
            url : "{:U('/Home/scanwifi/getappearmac','',false)}",
            type : "post",
            dataType : "json",
            data: null,
            timeout:6000,
            success:function(result){
                console.log(result);

                if(result.status==true){
                    $("#macname").html('');
                    for(var iloop=0; iloop<result.data.length;iloop++){
                        $("#macalert").show();
                        $("#macname").append('<h4 >'+
                            '告警标识：' + result.data[iloop]['alertname'] +
                            ' | mac：' + result.data[iloop]['s_mac']+
                            ' 在' + result.data[iloop]['timedesc'] + '出现！</h4>');
                    }
                }
            },
            error:function(msg){
                console.log(msg);
            }
        });
    }
    setInterval(getmacalert, 10000);

    var interval;
    $("#getroutemap").click(function () {
        $('#myrouteModal').modal('toggle');

        clearInterval(interval);
        interval=window.setInterval(getgps, 10000);
    });
    $('#myrouteModal').on('hide.bs.modal', function () {
        clearInterval(interval);
    });


    $("#wzwifi").click(function(){
        if($("#ssid").val().trim()==""){
            alert('请填写ssid');
            return;
        }
        if($("#key").val().length<8){
            alert('密码至少8位');
            return;
        }
        $(this).button('loading');
        var btn=$(this);
        var action="start";
        var xd = $("#xd").val();
        var ssid =  $("#ssid").val();
        var apmac = '主动伪装';
        var encrypt =  $("#encrypt").val();
        var key = $("#key").val();


        if($("#showstatus").css('width')=='55px'){
            $("#showstatus").css('width','40%');
            $("#subcurrentstatuslabel").show();
        }
        var htmls='SSID<span class="label label-success ">'+ssid+'</span> | 秘钥'+
            '<span class="label label-success ">' +key+'</span> | 加密方式' +
            '<span class="label label-success ">' +encrypt+'</span>';
        $("#wzwifistatus").html(htmls+'伪装开启中');

        $.ajax({
            url : "{:U('/Home/scanwifi/WZWifi','',false)}",
            type : "post",
            dataType : "json",
            data: {id:-1, xd: xd,ssid:ssid, encrypt:encrypt, key:key, apmac:apmac,action:action},
            timeout:6000,
            success:function(result){
                btn.button('reset');
                console.log(result);


                $('#myModal').hide();
                var wzhtml="SSID:"+ ssid +" 秘钥："+key+" 加密方式："+encrypt;
                //$("#wzstatus").html(wzhtml);

                $('#wzxd').val(xd);
                $('#wzssid').val(ssid);
                $('#wzencrypt').val(encrypt);
                $('#wzapmac').val('self');
                $('#wzkey').val(key);

                $("#wzwifistatus").html(htmls+'正在伪装中');

                if(action=="start"){
                    $("#mainwzwifi").attr('action','stop');
                    $("#mainwzwifi").html('停止伪装');
                    $("#mainwzwifi").attr('class','btn   btn-success btn-lg pull-right');
                }
                else{
                    $("#mainwzwifi").attr('action','start');
                    $("#mainwzwifi").html('开始伪装');
                    $("#mainwzwifi").attr('class','btn   btn-primary btn-lg pull-right');
                }
            },
            error:function(msg){
                $('#myModal').modal('toggle');
                console.log(msg);      //执行错误
                $("#wzwifistatus").html("执行失败："+ JSON.stringify(result));
                alert("系统错误!");
                btn.button('reset');
            }

        });
    });

    $("#mainwzwifi").click(function(){
        if($("#mainwzwifi").attr('action')=="start"){
            $('#myModal').modal('show');
        }
        else{
            var xd = $('#wzxd').val();
            var ssid = $('#wzssid').val();
            var encrypt = $('#wzencrypt').val();
            var apmac = $('#wzapmac').val();
            var action='stop'; //$('#action').val();
            var key=$('#wzkey').val();

            $("#wzwifistatus").html('暂无伪装任务');
            $("#mainwzwifi").attr('action','start');
            $("#mainwzwifi").html('开始伪装');
            $("#mainwzwifi").attr('class','btn   btn-primary btn-lg  pull-right');
            //$("#wzstatus").html('&nbsp;');
            $.ajax({
                url : "{:U('/Home/scanwifi/WZWifi','',false)}",
                type : "post",
                dataType : "json",
                data:{id:-1, xd: xd,ssid:ssid, encrypt:encrypt, key: key, apmac: apmac,action:action},
                timeout:30000,
                success:function(result){
                },
                error:function(msg){
                    console.log(msg);
                }

            });
        }
    });

    $("#miguan").click(function(){
        if($("#miguan").attr('action')=='start'){
            $('#myModalmiguan').modal('show');
        }
        else{
            $("#miguan").attr('action','start');
            $("#miguan").html('开启蜜罐');
            $("#miguan").attr('class','btn   btn-danger btn-lg  pull-left');
            $("#miguanstatus").html('&nbsp;');
            var action='stop';
            $.ajax({
                url : "{:U('/Home/index/APCamouflageAct','',false)}",
                type : "post",
                dataType : "json",
                data: {action:action,ssid:''},
                timeout:30000,
                success:function(result){
                },
                error:function(msg){
                    console.log(msg);
                }

            });
        }
    });

    $("#mainqxdyazhi").click(function(){
        var action=$("#mainqxdyazhi").attr('action');


        $.ajax({
            url : "{:U('/Home/scanwifi/QXDYazhi','',false)}",
            type : "post",
            dataType : "json",
            data:{action:action},
            timeout:30000,
            success:function(result){
                if($("#mainqxdyazhi").attr('action')=="start"){
                    $("#mainqxdyazhi").attr('action','stop');
                    $("#mainqxdyazhi").html('关闭全信道压制');
                    $("#mainqxdyazhi").attr('class','btn   btn-success btn-lg  pull-left');
                    $("#qxdyazhistatus").html("全信道压制运行中...");
                }else{
                    $("#mainqxdyazhi").attr('action','start');
                    $("#mainqxdyazhi").html('开启全信道压制');
                    $("#mainqxdyazhi").attr('class','btn   btn-danger btn-lg  pull-left');
                    $("#qxdyazhistatus").html("&nbsp;");
                }

            },
            error:function(msg){
                console.log(msg);
            }

        });
    });

    $("#setmiguan").click(function(){
        var file = document.getElementById("filenames").files[0];
        if(!file){
            alert('请上传蜜罐文件');
            return;
        }
        var reader = new FileReader();

        reader.readAsText(file);
        reader.onload = function()
        {
            $("#uploadfilecontent").val(this.result);
            var action='start';
            $.ajax({
                url : "{:U('/Home/index/APCamouflageAct','',false)}",
                type : "post",
                dataType : "json",
                data: {action:action,ssid:$("#uploadfilecontent").val()},
                timeout:30000,
                success:function(result){
                    console.log(result);

                    $('#myModalmiguan').modal('toggle');
                    var wzhtml="蜜罐运行中... ...";
                    $("#miguanstatus").html(wzhtml);
                    if(action=="start"){
                        $("#miguan").attr('action','stop');
                        $("#miguan").html('关闭蜜罐');
                        $("#miguan").attr('class','btn   btn-success btn-lg  pull-left');
                    }
                    else{
                        $("#miguan").attr('action','start');
                        $("#miguan").html('开启蜜罐');
                        $("#miguan").attr('class','btn   btn-danger btn-lg  pull-left');
                    }
                },
                error:function(msg){
                    console.log(msg);      //执行错误
                    alert("系统错误!");
                }

            });
        };

    });

    function getgps() {
        $.ajax({
            url : "{:U('/Home/Index/getgps','',false)}",
            type : "post",
            dataType : "json",
            data: null,
            timeout:30000,
            success:function(result){
                if(result.gps==""){
                    $("#gps").html('未知');
                }else{
                    $("#gps").html(result.gps);
                }
                //setmap(result.gps);
                setmap(result.gps);
            },
            error:function(msg){
                console.log(msg);      //执行错误
            }

        });
    }

    getgps();
    var lastgps="";
    var map = null;
    function setmap(gps) {
        if(map==null){
            map=new BMap.Map("allmap");
        }
        else
        {
            map.clearOverlays();
        }
        var points = new BMap.Point(108.018551,34.537307);
        map.centerAndZoom(points, 6);
        map.enableScrollWheelZoom();
        if(gps!=""){
            //map.clearOverlays();
            var lan=gps.split(' ');
            console.log(lan);
            var sContent =
                "<h4 style='margin:0 0 5px 0;padding:0.2em 0'>设备实时位置</h4>" +
                "<p style='margin:0;line-height:1.5;font-size:13px;text-indent:2em'>经纬度:"+gps+"</p>" ;
            // 百度地图API功能

            //坐标转换完之后的回调函数
            var point = new BMap.Point(lan[1], lan[0]);

            translateCallback = function (data){
                if(data.status === 0) {
                    var marker = new BMap.Marker(data.points[0]);
                    map.addOverlay(marker);
                    map.setCenter(data.points[0]);

                    var sContent =
                        "<h4 style='margin:0 0 5px 0;padding:0.2em 0'>WiFi位置</h4>" +
                        "<p style='margin:0;line-height:1.5;font-size:13px;text-indent:2em'>经纬度:" + gps + "</p>";
                    var infoWindow = new BMap.InfoWindow(sContent);  // 创建信息窗口对象

                    map.addOverlay(marker);
                    marker.openInfoWindow(infoWindow);
                    map.centerAndZoom(point, 15);
                    map.enableScrollWheelZoom();   //启用滚轮放大缩小，默认禁用
                }
            }

            var convertor = new BMap.Convertor();
            var pointArr = [];
            pointArr.push(point);
            convertor.translate(pointArr, 1, 5, translateCallback);



        }

    }





</script>

</html>
